
/**
 * 创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
 * 要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算
 */
/*import java.util.Scanner;
public class Test {
    public static int max3(int a,int b,int c) {
        int ret = max2(a,b);
        if(ret > c) {
            return ret;
        } else {
            return c;
        }
    }
    public static int max2(int a,int b) {
        if(a > b) {
            return a;
        } else {
            return b;
        }
    }
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        int c = 30;
        //max3(a,b,c);
        System.out.println(max2(a,b));
        System.out.println(max3(a,b,c));
    }
}*/

//求 N 的阶乘 。
/*
    import java.util.Scanner;
public class Test {
    public static int fac(int n) {
        if( n == 1) {
            return n;
        }
        return (n * fac(n - 1));
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int ret = fac(n);
        System.out.println(ret);
    }
}
*/

//求1！+2！+3！+4！+........+n!的和
/*
import java.util.Scanner;

public class Test {
    public static int facnum(int n) {
        int num = 0;
        for(int i = 1;i <= n;i++) {
            num += fac(i);
        }
        return num;
    }
    public static int fac(int i) {
        if(i == 1) {
            return i;
        }
        return i*fac(i-1);
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int ret = facnum(n);
        System.out.println(ret);
    }

}*/
//err代码
//求1！+2！+3！+4！+........+n!的和
import java.util.Scanner;
public class Test {
    public static int fac(int n) {
        if(n == 1) {
            return n;
        }
        int sum = 1;
        for (int i = 1; i <= n; i++) {
            sum *= i;
        }
        return sum + fac(n-1);
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int ret = fac(n);
        System.out.println(ret);
    }
}


//求斐波那契数列的第n项。(迭代实现)
/*    import java.util.Scanner;
public class Test {
    public static int fib(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        return (fib(n-1) + fib(n-2));

    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(fib(n));
    }
}*/


//在同一个类中,分别定义求两个整数的方法 和 三个小数之和的方法。 并执行代码，求出结果
/*
public class Test {
    public static int sum(int a,int b) {
        return a+b;
    }
    public static double sum(double a,double b,double c) {
        return a+b+c;
    }
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        double x = 1.0;
        double y = 2.0;
        double z = 3.0;
        System.out.println(sum(a,b));
        System.out.println(sum(x,y,z));
    }
}
*/


//在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
/*
public class Test {
    public static int maxNnm(int a,int b) {
        return a>b?a:b;
    }
    public static double maxNnm(double a,double b,double c) {
        if(a>b) {
            if(a>c) {
                return a;
            } else {
                return c;
            }
        } else {
            if(b>c) {
                return b;
            } else {
                return c;
            }
        }
    }
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        double x = 1.0;
        double y = 2.0;
        double z = 3.0;
        System.out.println(maxNnm(a,b));
        System.out.println(maxNnm(x,y,z));
    }
}*/
